package com.zhangshitong.springbootModel.mapper;

import com.zhangshitong.springbootModel.base.Page;
import com.zhangshitong.springbootModel.log.entity.BusinessLog;

/**
 * 
 * @author zst
 *
 */
public interface LogMapper {
	
	/**
	 * 分頁查詢 
	 * @param page
	 * @param condtion
	 * @return
	 */
	
	Page queryPage(Page page,BusinessLog log);

	/**
	 * 保存日志信息 
	 * @param log
	 * @return
	 */
	int saveLog(BusinessLog log);
	
	/**
	 * 查询日志分类累计统计(就是操作日志有多少访问，系统日志有多少访问)SELECT CASE `LOG_TYPE` WHEN '01' THEN '系统日志' ELSE '操作日志' END AS `name` ,COUNT(1) AS `value` FROM `sys_oper_log` GROUP BY `LOG_TYPE`
	 * @return
	 */
	Object queryLogTypeFx();
	/**
	 * 查询操作分类累计统计(统计“查询”、“新增”、“删除”、“修改”、“其他”的操作日志个数)
	 * SELECT
		CASE `OPER_TYPE`
		WHEN '01' THEN
			'新增'
		WHEN '02' THEN
			'删除'
		WHEN '03' THEN
			'修改'
		WHEN '04' THEN
			'查询'
		WHEN '05' THEN
			'其它'
		END AS `name`,
 	COUNT(1) AS `value`
		FROM
			`sys_oper_log`
		GROUP BY
			`OPER_TYPE`;
	 * @return
	 */
	Object queryOperTypeFx();
	
	/**
	 * 查询最近30天的数量
	 * SELECT
	t1.`day`,
	IFNULL(t2.`value`, 0) AS 'value'
FROM
	(
		SELECT
			DATE_FORMAT(create_date, '%Y-%m-%d') AS 'day'
		FROM
			`temp_date`
		WHERE
			TO_DAYS(NOW()) - TO_DAYS(`create_date`) >= 0
		AND TO_DAYS(NOW()) - TO_DAYS(`create_date`) <= 30
	) t1
LEFT JOIN (
	SELECT
		t.CNT AS `value`,
		DATE_FORMAT(
			DATE_ADD(NOW(), INTERVAL 0 - d DAY),
			'%Y-%m-%d'
		) AS `day`
	FROM
		(
			SELECT
				TO_DAYS(NOW()) - TO_DAYS(OPER_TIME) AS d,
				COUNT(1) AS CNT
			FROM
				`sys_oper_log`
			GROUP BY
				d
			HAVING
				d <= 30
		) t
) t2 ON t1. day = t2. day
	 * @return
	 */
	Object query30Day();
}
